package org.apache.struts.register.action;
import org.apache.struts.register.model.Person;
import org.apache.struts.register.util.HibernateUtils;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

public class HibernateTest1 {

        public static void main(String[] args) {

            //创建对象
            Person user = new Person();
            user.setFirstName("xu");
            user.setLastName("zhaopeng");

            //得到Session对象
            Session session = HibernateUtils.openSession();

            //使用Hibernate操作数据库，都要开启事务,得到事务对象
            Transaction transaction = session.getTransaction();

            //开启事务
            transaction.begin();

            //把对象添加到数据库中
            session.save(user);

            //提交事务
            transaction.commit();

            //关闭Session
            session.close();
        }
    }
